define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'anx.anx/index',
        add_url: 'anx.anx/add',
        edit_url: 'anx.anx/edit',
        delete_url: 'anx.anx/delete',
        export_url: 'anx.anx/export',
        modify_url: 'anx.anx/modify',
    
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh',
                            [
                                {
                                    text: '添加',
                                    url: init.add_url,
                                    method: 'open',
                                    auth: 'add',
                                    class: 'layui-btn layui-btn-normal layui-btn-sm',
                                    icon: 'fa fa-plus ',
                                    
                                }
                            ],
                        ],
                cols: [[
                    {field: 'title', title: '标题'},
                    {field: 'add_time', title: '添加时间',search: false},
                    {field: '', title: '是否发布', templet:function(d) {
                        if (d.status == 1) {
                            return '<a class="layui-btn layui-btn-sm"  data-request="anx.anx/fabu?id='+d.id+'" data-title="确定发布吗？" data-table="currentTableRenderId">发布</a>';
                        } else {
                            return '已发布';
                        }
                    }},
                    {
                        width: 200,
                        title: '操作',
                        templet: function (d) {
                            if (d.status == 1) {
                                return '<div class="layui-table-cell laytable-cell-1-0-5"><a class="layui-btn layui-btn-success layui-btn-xs" data-open="anx.anx/edit?id=${d.id}" data-title="编辑信息">编辑</a><a class="layui-btn layui-btn-danger layui-btn-xs" data-request="anx.anx/delete?id=${d.id}" data-title="确定删除？">删除</a></div>';
                            } else {
                                return '<div class="layui-table-cell laytable-cell-1-0-5"><a class="layui-btn layui-btn-danger layui-btn-xs" data-request="anx.anx/delete?id=${d.id}" data-title="确定删除？">删除</a></div>';

                            }
                        },
                    }
                ]],
            });
            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        }, 
        fabu: function () {
            ea.listen();
        },
    };
    return Controller;
});